package com.gidgabs.modules.api.controller.share;

import com.gidgabs.common.utils.ReturnJson;
import com.gidgabs.common.utils.UploadVideoUtils;
import com.gidgabs.common.validator.Assert;
import com.gidgabs.dto.VideoDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by tby on 2018/6/29.
 */
@Api("视频上传播放相关接口")
@RestController
@RequestMapping("api/video")
public class ApiVideoController {


    @ApiOperation(value = "获取上传凭证")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "title",value = "视频标题",dataType = "string",paramType = "query"),
            @ApiImplicitParam(name = "description",value = "视频描述",dataType = "string",paramType = "query"),
            @ApiImplicitParam(name = "fileName",value = "视频文件名称",dataType = "string",paramType = "query"),
            @ApiImplicitParam(name = "coverURL",value = "视频封面图片",dataType = "string",paramType = "query"),
            @ApiImplicitParam(name = "token",value = "token",dataType = "string",paramType = "header")
    })
    @RequestMapping(value = "uploadVideo", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
    public ReturnJson<VideoDto> uploadVideo(String title, String description, String fileName, String coverURL) {
        Assert.isBlank(title,"不能为空");
        //Assert.isBlank(description,"不能为空");
        //Assert.isBlank(fileName,"不能为空");
        Assert.isBlank(coverURL,"不能为空");
        VideoDto uploadVideo = UploadVideoUtils.createUploadVideo(title, description, fileName, coverURL);
        return ReturnJson.success("获取成功",uploadVideo);
    }

    @ApiOperation(value = "获取播放凭证")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "videoId",value = "视频id",dataType = "string",paramType = "query"),
            @ApiImplicitParam(name = "token",value = "token",dataType = "string",paramType = "header")
    })
    @RequestMapping(value = "videoPlayAuth", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
    public ReturnJson<VideoDto> videoPlayAuth(String videoId) {
        Assert.isBlank(videoId,"视频不能为空");

        VideoDto videoPlayAuth = UploadVideoUtils.getVideoPlayAuth(videoId);
        return ReturnJson.success("获取成功",videoPlayAuth);
    }
    @ApiOperation(value = "刷新播放凭证")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "videoId",value = "视频id",dataType = "string",paramType = "query")
    })
    @RequestMapping(value = "refreshVideoPlayAuth", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
    public ReturnJson<VideoDto> refreshVideoPlayAuth(String videoId) {
        Assert.isBlank(videoId,"视频不能为空");

        VideoDto videoPlayAuth = UploadVideoUtils.getVideoPlayAuth(videoId);
        return ReturnJson.success("获取成功",videoPlayAuth);
    }


}
